package service;
//import java.sql.Connection;
//import java.sql.PreparedStatement;
import java.util.List;

import util.TestConnection;
import model.users;
import dao.DaoProxy;
import dao.IUserDAO;
public class UserService implements IUserService{
	DaoProxy dao1=null;
	public UserService() throws Exception{
		super();
		dao1=new DaoProxy();
	}
	public boolean insertUser(users user) throws Exception  {
		if(dao1.findByName(user.getname())==null){
			dao1=new DaoProxy();
			return dao1.insertUser(user);}
		return false;
	}
	public boolean updateUser(users user ) throws Exception{
		return dao1.updateUser(user);
	}
	public boolean deleteUser(int Id)throws Exception {
		return dao1.deleteUser(Id);
	}
	public List<users> findAll() throws Exception {
		return dao1.findAll();
	}
	public users findByName(String name) throws Exception {
		return dao1.findByName(name);
	}
	
	public boolean checkName(String name,String password) throws Exception{
		//users user = dao1.findByName(name);
		//if(user!=null&&password.equals(user.getpassword()))
		//	return true;
		//return false;
		boolean test=false;
		users user=null;
		if(dao1.IsName(name))
			test=false;//用户名不存在
		else{
			dao1=new DaoProxy();
			user=dao1.findByName(name);
			if(user.getpassword().equals(password))
				test=true;
		}
		return test;
	}
	public boolean IsName(String name) throws Exception {
		return dao1.IsName(name);
	}
	@Override
	public users findById(int Id) throws Exception {
	   return dao1.findById(Id);
	}
	
}